"""
需求：从终端输入搜索关键字，保存HTML页面到本地
"""
import requests
from urllib import parse

# 1. 拼接地址
keyword = input("请输入关键字：")
params = parse.urlencode({"kw":keyword})

headers = {
    "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"
}
url="https://tieba.baidu.com/f?{}".format(params)

# 2. 发送请求获取响应内容
html = requests.get(url=url,headers=headers).text

# 3. 保存文件到本地
filename = "{}.html".format(keyword)
with open(filename,"w",encoding="utf-8") as f:
    f.write(html)





